<?php
/**
 * AlipayConfig.php
 *
* 跨境电商商城系统
 * =============================================
 * Copy right 2016-2026 大连熠泽科技网络有限公司
 * ---------------------------------------------
 * 官方网址: http://www.yizehuitong.com
 * =============================================
 * @author : yizehuitong
 * @date : 2019.10
 * @version : v2.0
 */

namespace addons\NsWeixinpay\data\service;


use data\model\NsOrderPaymentModel;
use data\service\BaseService;
use data\service\UnifyPay;
use addons\NsWeixinpay\data\service\WeiXinPay;

/**
 * 支付宝支付配置
 */
class Pay extends BaseService
{
	
	/**
	 * 执行微信支付
	 */
	public function wchatPay($out_trade_no, $trade_type, $red_url, $applet_openid = "")
	{
		$unify_pay = new UnifyPay();
		$data = $unify_pay->getPayInfo($out_trade_no);
        if (empty($data) < 0) {
            return 0;
        }
        //修改支付方式
        $unify_pay->modifyOrderPaymentType($out_trade_no, 1);

		$weixin_pay = new WeiXinPay();
		if ($trade_type == 'JSAPI') {
			$openid = $weixin_pay->get_openid();
			$product_id = '';
		}
		if ($trade_type == 'NATIVE') {
			$openid = '';
			$product_id = $out_trade_no;
		}
		if ($trade_type == 'MWEB') {
			$openid = '';
			$product_id = $out_trade_no;
		}
		if ($trade_type == 'APPLET') {
			$openid = $applet_openid;
		}
		
		$retval = $weixin_pay->setWeiXinPay($data['pay_body'], $data['pay_detail'], $data['pay_money'] * 100, $out_trade_no, $red_url, $trade_type, $openid, $product_id);
		return $retval;
	}
	/**
	 * 获取微信jsapi
	 */
	public function getWxJsApi($UnifiedOrderResult)
	{
		$weixin_pay = new WeiXinPay();
		$retval = $weixin_pay->GetJsApiParameters($UnifiedOrderResult);
		return $retval;
	}

	/**
	 * 微信支付检测签名串
	 */
	public function checkSign($post_obj, $sign)
	{
		$weixin_pay = new WeiXinPay();
		$retval = $weixin_pay->checkSign($post_obj, $sign);
		return $retval;
	}

	/**
	 * 微信退款
	 */
	public function setWeiXinRefund($refund_no, $out_trade_no, $refund_fee, $total_fee)
	{
		$weixin_pay = new WeiXinPay();
		$retval = $weixin_pay->setWeiXinRefund($refund_no, $out_trade_no, $refund_fee, $total_fee);
		return $retval;
	}

	/**
	 * 提现 微信转账
	 */
	public function wechatTransfers($openid, $partner_trade_no, $amount, $realname, $desc)
	{
		$weixin_pay = new WeiXinPay();
		$retval = $weixin_pay->EnterprisePayment($openid, $partner_trade_no, $amount, $realname, $desc);
		return $retval;
	}

    /**
     * 订单关闭
     * @param $out_trade_no
     * @return unknown
     */
	public function setOrderClose($out_trade_no){
        $weixin_pay = new WeiXinPay();
        $retval = $weixin_pay->setOrderClose($out_trade_no);
        return $retval;
    }
}